<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class RoleUser extends Model
{
    use HasFactory;

    const POSTONLY = [
        'user_id',
        'role_id',
        'cert_id',
        'status',
        'project_id'
    ];
    protected $fillable = [
        'user_id',
        'role_id',
        'cert_id',
        'status',
        'project_id'
    ];

    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    public function user()
    {
        return $this->hasOne(User::class,'id','user_id')->select('id','name','mobile');
    }

    public function role()
    {
        return $this->hasOne(Role::class,'id','role_id')->select('id','name');
    }

    public function cert()
    {
        return $this->hasOne(Cert::class,'id','cert_id')->select('id','title','numbers');
    }
}
